package com.evildog.workspace.invest.application.controller;

import com.evildog.workspace.common.object.PageQuery;
import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.invest.application.bo.BillReportListBO;
import com.evildog.workspace.invest.application.bo.BillReportPageBO;
import com.evildog.workspace.invest.application.bo.BillReportStatBO;
import com.evildog.workspace.invest.application.convert.BillReportConvert;
import com.evildog.workspace.invest.application.model.BillReportListParam;
import com.evildog.workspace.invest.application.model.BillReportPageParam;
import com.evildog.workspace.invest.application.service.BillReportService;
import com.evildog.workspace.invest.application.vo.BillReportListVO;
import com.evildog.workspace.invest.application.vo.BillReportPageVO;
import com.evildog.workspace.invest.application.vo.BillReportYearStatVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * billReport Controller
 * 记账报告
 * </p>
 *
 * @author evildog
 * @since 2020-08-06
 */
@RestController
@RequestMapping("/bill-reports")
@AllArgsConstructor
@Api(tags = "billReport相关接口")
public class BillReportController {

    private BillReportService billReportService;

    @GetMapping("/page")
    @ApiOperation(value = "表分页查询接口")
    public Result<PagedResult<BillReportPageVO>> getPageList(BillReportPageParam billReportPageParam, PageQuery query) {
        PagedResult<BillReportPageBO> billReportPageBO = billReportService.getPageList(
                query,
                QueryConditionUtils.getQueryCondition(billReportPageParam),
                BillReportConvert.INSTANCE.convert(billReportPageParam));
        return ResultGenerator.success(BillReportConvert.INSTANCE.convert(billReportPageBO));
    }

    @GetMapping
    @ApiOperation(value = "表List查询接口")
    public Result<List<BillReportListVO>> getList(BillReportListParam billReportListParam) {
        List<BillReportListBO> billReportListBO = billReportService.getList(
                QueryConditionUtils.getQueryCondition(billReportListParam),
                BillReportConvert.INSTANCE.convert(billReportListParam));
        return ResultGenerator.success(BillReportConvert.INSTANCE.convertVoList(billReportListBO));
    }

    @GetMapping("/year-statistics")
    @ApiOperation(value = "获取当前支出统计信息")
    public Result<BillReportYearStatVO> getYearStatistics(@RequestParam Integer year) {
        BillReportStatBO billReportListBO = billReportService.getStatistics(year);
        return ResultGenerator.success(BillReportConvert.INSTANCE.convert(billReportListBO));
    }

}